package com.example.dense_rack_server.utils;

public class test {

    // 每列的板子数量（每8位一个板子，每列16位）
    private static final int BOARDS_PER_COLUMN = 2;

    public static void main(String[] args) {
        int layers = 10; // 总层数
        int columns = 6; // 总列数

        // 示例调用
        for (int layer = 1; layer <= layers; layer++) {
            for (int column = 1; column <= columns; column++) {
                for (int position = 1; position <= 16; position++) {
                    int adrAddress = calculateAdrAddress(layers, columns, layer, column, position);
                    System.out.println("Layer " + layer + ", Column " + column + ", Position " + position + ": adr " + adrAddress);
                }
            }
        }
    }

    /**
     * 计算adr地址
     * @param totalLayers 总层数
     * @param totalColumns 总列数
     * @param layer 当前层数
     * @param column 当前列数
     * @param position 当前位置（1到16）
     * @return adr地址
     */
    public static int calculateAdrAddress(int totalLayers, int totalColumns, int layer, int column, int position) {
        if (position < 1 || position > 16) {
            throw new IllegalArgumentException("Position must be between 1 and 16.");
        }

        // 计算当前板子的索引
        int baseIndex = (layer - 1) * (totalColumns * BOARDS_PER_COLUMN) + (column - 1) * BOARDS_PER_COLUMN;

        // 根据位置确定板子的adr地址
        if (position <= 8) {
            return baseIndex + 1;
        } else {
            return baseIndex + 2;
        }
    }
}
